/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2021并保留所有权利。
 * Copyright 2021, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.threapool.executor_submit;

import org.junit.Test;

import java.util.concurrent.*;

public class ForkJoinPoolTest {
//    private static Logger log = LoggerFactory.getLogger(ForkJoinPoolTest.class.getSimpleName());
    private static final int threads = 3;
    CountDownLatch countDownLatch = new CountDownLatch(threads);
 
    @Test
    public void test1() throws InterruptedException {
        System.out.println("-------- begin ----------");
        ForkJoinPool forkJoinPool = new ForkJoinPool();
//        ExecutorService forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors());
        for (int i = 0; i < threads; i++) {
            forkJoinPool.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        System.out.println("getParallelism=" + forkJoinPool.getParallelism());
                        System.out.println("getStealCount=" + forkJoinPool.getStealCount());
                        System.out.println(Thread.currentThread().getName());
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        countDownLatch.countDown();
                    }
                }
            });
        }
        countDownLatch.await();
        System.out.println("-------- end ----------");
    }
}